<?php
/**
 * Catalog product controller
 *
 * @category   Mage
 * @package    Mage_Adminhtml
 * @author      Magento Core Team <core@magentocommerce.com>
 */
require_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
class Webkul_Marketplacepartner_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
    public function massDeleteAction(){
		$mysqlprefix = Mage::getConfig()->getTablePrefix();//code for mysql prefix
        $productIds = $this->getRequest()->getParam('product');
        if (!is_array($productIds)) {
            $this->_getSession()->addError($this->__('Please select product(s).'));
        } else {
            if (!empty($productIds)) {
                try {
					foreach ($productIds as $productId) {
						$product = Mage::getSingleton('catalog/product')->load($productId);
						Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product));
						$product->delete();
						// delete product from customer partner model
						require_once Mage::getBaseDir('app').'/Mage.php';
						$write = Mage::getSingleton('core/resource')->getConnection('core_write');
						$readresult=$write->query("select customerpartnerproductid from ".$mysqlprefix."marketplacepartner_entity_data where mageproductid='$productId'");
						$row = $readresult->fetch();
						Mage::getModel('marketplacepartner/marketplacepartner_product')->load($row['customerpartnerproductid'])->delete();
						$querydata=$write->query("delete from ".$mysqlprefix."marketplacepartner_entity_data where mageproductid='$productId'");
					}
					$message = Mage::helper('marketplacepartner')->__('Total of ');
					$message .= count($productIds);
					$message .= Mage::helper('marketplacepartner')->__(' record(s) have been deleted.');
					$this->_getSession()->addSuccess($message);
                } catch (Exception $e) {$this->_getSession()->addError($e->getMessage());}
            }
        }
        $this->_redirect('*/*/index');
	}
}
